<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>05_jQuery-解决命名冲突</title>
</head>
<body>

  <script>
    // 给window 添加了 $ / jQuery 变量
    var $ = '$-解决命名冲突'
    var jQuery = 'jQuery-解决命名冲突'
  </script>
  <script src="../libs/jquery-3.6.0.js"></script>
  <script>

    console.log('$O', $); // $O ƒ ( selector, context ) {
                        // The jQuery object is actually just the init constructor 'enhanced'
                        // Need init if jQuery is called (just allow error to be thrown if not included)
                        // return new jQuery…
    
    console.log($('body')); // jQuery.fn.init(1) [body]
    
    // 1.解决 $ 变量的冲突
    // jQuery.noConflict() // window.$ =  _$
    // console.log( $, jQuery ); // $-解决命名冲突 ƒ ( selector, context ) {
    // The jQuery object is actually just the init constructor 'enhanced'
    // Need init if jQuery is called (just allow error to be thrown if not included)
    // return new jQuery…

    // 2. 解决 jQuery 和 $ 变量的冲突
    var newjQuery = jQuery.noConflict(true) // window.$ =  _$ ;  window.jQuery =  _jQuery
    console.log( $ ) // $-解决命名冲突
    console.log( jQuery ) // jQuery-解决命名冲突

    console.log(newjQuery)
  </script>
  
</body>
</html>